package com.gdones.bootserver.bus.log.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gdones.bootserver.bus.log.dto.Log;
import com.gdones.bootserver.bus.log.mapper.LogMapper;
import com.gdones.bootserver.bus.log.service.ILogService;
import com.gdones.common.core.dto.MyPageBand;
import com.gdones.common.core.dto.MyPager;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author GaoJingBo
 * @since 2023-03-23
 */
@Service
public class LogServiceImpl extends ServiceImpl<LogMapper, Log> implements ILogService {

    @Override
    public MyPager<Log> myPage(Log syslog, MyPageBand pageBand) {

        LogMapper mapper = this.getBaseMapper();

        // 定义一个自定义分页接口
        IPage<Log> pages = mapper.myPage(PageDTO.of(pageBand.getPage(),pageBand.getSize()),syslog);

        // 根据分页的结果封装返回数据
        MyPager<Log> pager = new MyPager<>();
        pager.setTotal(pages.getTotal());
        pager.setPage(pageBand.getPage());
        pager.setPageSize(pageBand.getSize());
        pager.setRows(pages.getRecords());

        return pager;
    }

    @Override
    public List<String> getModels() {

        LogMapper mapper = this.getBaseMapper();

        List<String> modelNames = mapper.getModels();

        return modelNames;
    }
}
